package com.cuihanyu.newuniversityover.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.cuihanyu.newuniversityover.R;
import com.cuihanyu.newuniversityover.util.CodeUtils;
import com.cuihanyu.newuniversityover.util.SPUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by cuihanyu on 2018/4/3.
 */

public class LoginActivity extends AppCompatActivity {
    @BindView(R.id.DL_Button)
    Button mDL_Button;
    @BindView(R.id.name)
    EditText mName;
    @BindView(R.id.Phone_number)
    EditText mPhone_number;
    @BindView(R.id.ZC)
    TextView mZC;
    private Intent intent;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        ButterKnife.bind(this);
        intent = new Intent();
        initView();
    }

    private void initView() {
    }

    @OnClick({R.id.DL_Button, R.id.ZC})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.DL_Button:
                if (SPUtils.get(this, "Name", "").equals(mName.getText().toString()) &&
                        !mName.getText().toString().isEmpty() &&
                        SPUtils.get(this, "Phone", "").equals(mPhone_number.getText().toString()) &&
                        !mPhone_number.getText().toString().isEmpty()) {
                    Toast.makeText(this, "登陆成功~", Toast.LENGTH_SHORT).show();
                    intent.putExtra("Name",mName.getText().toString());
                    setResult(1,intent);
                    finish();
                } else {
                    Toast.makeText(this, "输入的信息不正确~", Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.ZC:
                intent.setClass(LoginActivity.this,RegisterActivity.class);
                startActivityForResult(intent,1);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (resultCode){
            case 1:
                mName.setText(data.getStringExtra("Name"));
                mPhone_number.setText(data.getStringExtra("Phone"));
                break;
        }
    }
}
